package com.example.smartclassroom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.smartclassroom.entity.CourseSelection;
import com.example.smartclassroom.entity.request.CourseRequest;
import com.example.smartclassroom.entity.vo.CourseVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CourseSelectionMapper extends BaseMapper<CourseSelection> {



    /**
     * 查询学生本人，老师本人所有课程信息
     * @param courseSelection
     * @return
     */
    Page<CourseVo>  selectAll(Page<CourseVo> page,@Param("courseSelection") CourseRequest courseSelection);

    /**
     * 查询学生本人，老师本人所有课程信息、以便导出
     * @param studentId
     * @return
     */
    List<CourseSelection>  selectAllOut(Integer studentId);


    /**
     * 查询学生本人所有课程信息
     */
    List<CourseSelection> selectCourseByStudentId(Integer studentId);


    /**
     * 通过课程id查询课程安排个数
     * @param courseId
     * @return
     */
    @Select("select count(*) from course_selection where course_id = #{courseId}")
    List<CourseSelection> selectCourseByCourseId(Integer courseId);

    @Select("select count(*) from course_selection where student_id = #{studentId}")
    Integer queryTotalByStudentId(Integer studentId);

    /**
     * 通过学生id和课程id删除课程
     */
    @Select("delete from course_selection where student_id = #{studentId} and course_id = #{courseId}")
    Integer deleteCourseByStudentIdAndCourseId(Integer studentId,Integer courseId);


    /**
     * 学生添加选课课程
     */
    @Insert("insert into course_selection(student_id, course_id) values(#{studentId}, #{courseId})")
    Integer studentAddCourse(Integer studentId,Integer courseId);
}
